#!/usr/bin/python
#coding:utf-8

'''
显示堆积图
'''
import numpy as np
import matplotlib.pyplot as plt

from pylab import mpl
mpl.rcParams['font.sans-serif'] = ['FangSong'] # 指定默认字体
mpl.rcParams['axes.unicode_minus'] = False # 解决保存图像是负号'-'显示为方块的问题

def pic2():
    '''
    x轴上下显示
    '''
    n = 12
    X = np.arange(n)
    Y1 = (1 - X/float(n)) * np.random.uniform(0.5, 1.0, n)
    Y2 = (1 - X/float(n)) * np.random.uniform(0.5, 1.0, n)

    plt.figure(figsize=(12, 8))
    plt.bar(X, +Y1, facecolor='#9999ff', edgecolor='white')
    plt.bar(X, -Y2, facecolor='#ff9999', edgecolor='white')

    for x, y in zip(X,Y1):
        # ha: horizontal alignment水平方向
        # va: vertical alignment垂直方向
        plt.text(x, y+0.05, '%.2f' % y, ha='center', va='bottom')

    for x, y in zip(X,-Y2):
        # ha: horizontal alignment水平方向
        # va: vertical alignment垂直方向
        plt.text(x, y-0.05, '%.2f' % y, ha='center', va='top')

    # 定义范围和标签
    plt.xlim(-.5, n)
    plt.xticks(())
    plt.ylim(-1.25, 1.25)
    plt.yticks(())

    plt.show()


def duiji():
    '''
    堆积图
    '''
    c1="#99CCFF"
    c2="#CCFFFF"
    c3="#6699CC"

    year=['2007','2008','2009','2010','2011','2012','2013','2014','2015','2016']
    children=np.array([25660,25166,24659,22259,22164,22287,22329,22558,22715,23008])
    adults=np.array([95833,96680,97484,99938,100283,100403,100582,100469,100361,100260])
    seniors=np.array([10636,10956,11307,11894,12288,12714,13161,13755,14386,15003])

    x=np.arange(len(year))
    width=0.5
    fig,ax=plt.subplots()
    ax.bar(x,children,width,color=c1,edgecolor='g')
    ax.bar(x,adults,width,children,color=c2,edgecolor='b')
    ax.bar(x,seniors,width,children+adults,color=c3,edgecolor='r')

    ax.set_xticks(x)
    ax.set_xticklabels(year)
    plt.show()

def  showAll(img,modelimg,resultimg):
    '''
    显示多种图片，三种图片必须为numpy格式
    '''
    f, axarr = plt.subplots(2, 2)
    axarr[0, 0].set_title('原始图片')
    axarr[0, 1].set_title('剪裁图')

    axarr[1, 0].set_title('模型图')


    axarr[0, 0].imshow(img)
    axarr[0, 1].imshow(resultimg)

    axarr[1, 0].imshow(modelimg)

    #全屏显示
    # plt.get_current_fig_manager().full_screen_toggle()
    #窗口最大化
    figManager = plt.get_current_fig_manager()
    figManager.window.showMaximized()  
    plt.show()

def main():
    duiji()

if __name__ == '__main__':
    main()